home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
util1
/
yk211src.lha
/
Yak_2.11_Src
/
Prefs
/
BGUI
/
Root_window.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-16
|
32KB
|
669 lines
/************************************************************************
************************** BGUI ROOT WINDOW ***************************
************************************************************************/
#define __USE_SYSBASE
#include <exec/memory.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/bgui.h>
#include <libraries/bgui_macros.h>
#include <libraries/asl.h>
#include <workbench/workbench.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/bgui.h>
#include <proto/icon.h>
#include <proto/wb.h>
#include <proto/asl.h>
#include <clib/alib_protos.h>
#include <string.h>
#include <stdlib.h>
#include "code.h"
#include "version.h"
#include "yak.h"
#include "hotkey_types.h"
#include "gui.h"
#include "filereq.h"
#include "Requesters.h"
#include "Settings.h"
#include "Root_Window.h"
#include "Root_Menus.h"
#define CATCOMP_NUMBERS
#include "locale/yak_locale_strings.h"
/************************************************************************
***************************** REFERENCES ******************************
************************************************************************/
IMPORT LONG (*HandleReturnID)(LONG ID);
IMPORT BOOL CreateIcons;
IMPORT char *ProgramName;
IMPORT char *PrefsFile;
IMPORT char *PrefsHelp;
IMPORT struct NotifyRequest NotifyRequest;
/************************************************************************
***************************** LOCAL DATA ******************************
************************************************************************/
struct Window *RootWnd = NULL;
Object *RootWndObj = NULL;
Object *RootObjects[Root_CNT];
UBYTE *RootWdt;
struct IBox RootBox;
BOOL RootBoxValid = FALSE;
BOOL RootWdi = FALSE;
/************************************************************************
************************* CREATEROOTWINDOW() **************************
*************************************************************************
* Create the root window object tree. Returns the window object ptr or
* NULL if create failed. Gadgets are initialised with default values,
* InitRootGadgets must be called after window opened to reflect current
* settings.
*
*************************************************************************/
APTR CreateRootWindow(VOID)
{
Object *obj,*indicobj;
/* maplist: converts slider level tag to indicator level tag */
static struct TagItem SliderToIndicMap[] = {
SLIDER_Level, INDIC_Level, TAG_DONE
};
obj = WindowObject,
WINDOW_PubScreenName, PubScreenName,
WINDOW_Title, RootWdt,
WINDOW_ScreenTitle, getString(COPYRIGHT_STRING),
WINDOW_SmartRefresh, TRUE,
WINDOW_SizeBottom, FALSE, /* put size gadget in right border */
WINDOW_SizeRight, TRUE,
WINDOW_AutoAspect, TRUE, /* automatic edges pixel width */
WINDOW_Position, POS_CENTERMOUSE,
(RootBoxValid ? WINDOW_Bounds : TAG_IGNORE), &RootBox,
WINDOW_AppWindow, TRUE, /* make it an appwindow */
WINDOW_MenuStrip, RootNewMenu,
WINDOW_CloseGadget, FALSE,
(TextFont ? WINDOW_Font : TAG_IGNORE), &Attr, /* use font if specified */
WINDOW_HelpFile, PrefsHelp, /* online help system */
WINDOW_HelpNode, "MainWindow",
WINDOW_MasterGroup,
VGroupObject, Spacing(4), HOffset(4), VOffset(4),
StartMember,
/* windows activation group */
HGroupObject, Spacing(24), HOffset(6), VOffset(4),
/* add frame & title to Windows Activation group */
NeXTFrame,
FRM_Title, getString(WINDOWS_ACTIVATE_STRING),
FRM_Flags, FRF_EDGES_ONLY|FRF_CENTER_TITLE|FRF_HIGHLIGHT_TITLE,
StartMember,
VGroupObject, Spacing(2),
StartMember,
CH_KeyActivate = CheckBoxObject,
LAB_Label, getString(KEY_ACTIVATE_STRING),
LAB_Place, PLACE_RIGHT,
GA_ID, GD_KeyActCheck,
ButtonFrame,
FRM_Flags, FRF_EDGES_ONLY,
EndObject, FixMinWidth,
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
CH_MMBActivate = CheckBoxObject,
LAB_Label, getString(MMB_ACTIVATE_STRING),
LAB_Place, PLACE_RIGHT,
GA_ID, GD_MMBActCheck,
ButtonFrame,
FRM_Flags, FRF_EDGES_ONLY,
EndObject, FixMinWidth,
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
CH_RMBActivate = CheckBoxObject,
LAB_Label, getString(RMB_ACTIVATE_STRING),
LAB_Place, PLACE_RIGHT,
GA_ID, GD_RMBActCheck,
ButtonFrame,
FRM_Flags, FRF_EDGES_ONLY,
EndObject, FixMinWidth,
EndMember,
EndObject,
EndMember,
StartMember,
VGroupObject, Spacing(2),
StartMember,
CH_AutoPoint = CheckBoxObject,
LAB_Label, getString(AUTOPOINT_STRING),
LAB_Place, PLACE_RIGHT,
GA_ID, GD_AutoCheck,
ButtonFrame,
FRM_Flags, FRF_EDGES_ONLY,
EndObject, FixMinWidth,
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
STR_AutoScreen = StringObject,
LAB_Label, getString(AUTOSCREENS_STRING),
RidgeFrame,
STRINGA_MaxChars,99,
STRINGA_MinCharsVisible,12,
GA_ID, GD_AutoPat,
GA_TabCycle, TRUE,
EndObject,
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
HGroupObject, Spacing(2),
StartMember,
SL_AutoPointDelay = SliderObject,
LAB_Label, getString(AUTOPOINT_DELAY_STRING),
SLIDER_Min, 0,
SLIDER_Max, 5,
SLIDER_Level, 0,
GA_ID, GD_AutoPointDelay,
EndObject,
EndMember,
StartMember,
indicobj = IndicatorObject,
INDIC_Min, 0,
INDIC_Max, 5,
INDIC_Level, 0,
INDIC_FormatString,"%1lu",
INDIC_Justification,IDJ_CENTER,
EndObject, Weight(DEFAULT_WEIGHT/10),
EndMember,
EndObject,
EndMember,
EndObject,
EndMember,
EndObject, Weight(DEFAULT_WEIGHT*3),
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
HGroupObject, Spacing(2),
StartMember,
/* screens activation group */
VGroupObject, /*Spacing(2), */HOffset(6), VOffset(4),
/* add frame & title to screens activation group */
NeXTFrame,
FRM_Title, getString(SCREEN_ACTIVATE_STRING),
FRM_Flags, FRF_EDGES_ONLY|FRF_CENTER_TITLE|FRF_HIGHLIGHT_TITLE,
StartMember,
CH_ScreensActivation = CheckBoxObject,
LAB_Label, getString(SCREEN_ACTIVATE_STRING),
LAB_Place, PLACE_RIGHT,
GA_ID, GD_ScrActCheck,
ButtonFrame,
FRM_Flags, FRF_EDGES_ONLY,
EndObject, FixMinWidth,
EndMember,
VarSpace(DEFAULT_WEIGHT*11/10),
EndObject, Weight(DEFAULT_WEIGHT/3),
EndMember,
VarSpace(DEFAULT_WEIGHT/20),
StartMember,
VGroupObject, Spacing(2),
StartMember,
/* autopoptofront group */
VGroupObject, /*Spacing(2), */HOffset(6), VOffset(4),
/* add frame & title to autopoptofront group */
NeXTFrame,
FRM_Title, getString(AUTOPOPTOFRONT_STRING),
FRM_Flags, FRF_EDGES_ONLY|FRF_CENTER_TITLE|FRF_HIGHLIGHT_TITLE,
StartMember,
CH_AutoPopToFront = CheckBoxObject,
LAB_Label, getString(AUTOPOPTOFRONT_STRING),
LAB_Place, PLACE_RIGHT,
GA_ID, GD_AutoPopCheck,
ButtonFrame,
FRM_Flags, FRF_EDGES_ONLY,
EndObject, FixMinWidth,
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
STR_PopWindows = StringObject,
LAB_Label, getString(POPWINDOWS_STRING),
RidgeFrame,
STRINGA_MaxChars,99,
STRINGA_MinCharsVisible,12,
GA_ID, GD_PopPat,
GA_TabCycle, TRUE,
EndObject,
EndMember,
EndObject,
EndMember,
EndObject,
EndMember,
EndObject, Weight(DEFAULT_WEIGHT*2),
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
HGroupObject, Spacing(2),
StartMember,
BT_MouseCycling = Button(
getString(MOUSECYCLING_STRING),
GD_MouseCycling),
EndMember,
StartMember,
BT_Blanking = Button(
getString(Blanking),
GD_Blanking),
EndMember,
EndObject,
EndMember,
StartMember,
HGroupObject, Spacing(2),
StartMember,
BT_EditHotkeys = Button(
getString(EDIT_HOTKEYS_STRING),
GD_EditHotkeys),
EndMember,
StartMember,
BT_Miscellaneous = Button(
getString(MISCELLANEOUS_STRING),
GD_Miscellaneous),
EndMember,
EndObject,
EndMember,
VarSpace(DEFAULT_WEIGHT/10),
StartMember,
HorizSeparator,
EndMember,
StartMember,
HGroupObject, Spacing(2),
StartMember,
BT_Save = Button(getString(SAVE_STRING),GD_Save),
EndMember,
VarSpace(DEFAULT_WEIGHT/3),
StartMember,
BT_Use = Button(getString(USE_STRING),GD_Use),
EndMember,
VarSpace(DEFAULT_WEIGHT/3),
StartMember,
BT_Cancel = Button(getString(CANCEL_STRING),GD_Cancel0),
EndMember,
EndObject,
EndMember,
EndObject,
EndObject;
if (obj)
{
/* set tab cycle order between string gadgets */
DoMethod(obj,WM_TABCYCLE_ORDER,STR_AutoScreen,STR_PopWindows,NULL);
/* add map from slider to its level indicator */
AddMap(SL_AutoPointDelay,indicobj,SliderToIndicMap);
/* add conditional map: disables STR_AutoScreen and */
/* SL_AutoPointDelay when CH_AutoPoint is unchecked */
AddCondit(CH_AutoPoint,STR_AutoScreen,GA_Selected,TRUE,
GA_Disabled,FALSE,GA_Disabled,TRUE);
AddCondit(CH_AutoPoint,SL_AutoPointDelay,GA_Selected,TRUE,
GA_Disabled,FALSE,GA_Disabled,TRUE);
/* add conditional map: disables STR_PopWindows */
/* when CH_AutoPopToFront is unchecked */
AddCondit(CH_AutoPopToFront,STR_PopWindows,GA_Selected,TRUE,
GA_Disabled,FALSE,GA_Disabled,TRUE);
}
return(obj);
}
/************************************************************************
************************* INITIALIZE GADGETS **************************
*************************************************************************
* Initialize the root window gadgets to reflect current settings.
*
*************************************************************************/
static void InitAutoPointGadgets(void)
{
InitWindowGadget(GDX_AutoPat, STRINGA_TextVal, (LONG)patterns[YP_AUTOSCR_PAT].patstr, ROOT_WINDOW);
InitWindowGadget(GDX_AutoPat, GA_Disabled, !autopoint, ROOT_WINDOW);
InitWindowGadget(GDX_AutoPointDelay, SLIDER_Level, autopoint_delay, ROOT_WINDOW);
InitWindowGadget(GDX_AutoPointDelay, GA_Disabled, !autopoint, ROOT_WINDOW);
}
static void InitAutoPopGadgets(void)
{
InitWindowGadget(GDX_PopPat, STRINGA_TextVal, (LONG)patterns[YP_POPWIN_PAT].patstr, ROOT_WINDOW);
InitWindowGadget(GDX_PopPat, GA_Disabled, !autopop, ROOT_WINDOW);
}
static void InitRootGadgets(void)
{
InitToggleGadgets(ROOT_WINDOW);
InitAutoPopGadgets();
InitAutoPointGadgets();
}
/************************************************************************
************************** CLOSEROOTWINDOW() **************************
*************************************************************************
* Close the root window, disposing of the root window object.
*
*************************************************************************/
void CloseRootWindow(void)
{
if (RootWnd)
{
GetAttr(WINDOW_Bounds,RootWndObj,(ULONG *) &RootBox);
RootBoxValid = TRUE;
}
DisposeObject(RootWndObj);
RootWndObj = NULL;
RootWnd = NULL;
}
/************************************************************************
************************** SHOWROOTWINDOW() ***************************
*************************************************************************
* Create and open the root window and initialize the gadgets to reflect
* current settings. Sets up HandleReturnID function, curwin, curwinobj
* and curwinID. Returns TRUE or FALSE to indicate success.
*
*************************************************************************/
BOOL ShowRootWindow(void)
{
static char title[80];
if (!RootWdi)
{
RootWdi = TRUE;
strcpy(title, getString(Prefs_Window_TITLE));
strcat(title, " : ");
strcat(title,VERSION_NAME);
RootWdt = title;
InitRootNewMenu ();
}
if (RootWndObj = (Object *)CreateRootWindow())
{
if (RootWnd = WindowOpen(RootWndObj))
{
InitRootGadgets();
HandleReturnID = HandleRootReturnID;
curwin = RootWnd;
curwinobj = RootWndObj;
curwinID = ROOT_WINDOW;
return(TRUE);
}
}
CloseRootWindow();
curwin = NULL;
curwinobj = NULL;
wndsigflag = 0L;
appwinsigflag = 0L;
return(FALSE);
}
/************************************************************************
************************ HANDLEROOTRETURNID() *************************
*************************************************************************
* Handle msgs arriving at root window - supply the ID returned by BGUI.
* Returns either RET_OKAY or RET_QUIT.
*
*************************************************************************/
LONG HandleRootReturnID(LONG id)
{
LONG ret;
ret = RET_OKAY;
switch(id)
{
case GD_EditHotkeys:
if (!SwitchFromRootWindow(HOTKEY_WINDOW))
{
PostError(getString(Couldnt_open_other_window_ERR));
ret = RET_QUIT;
}
break;
case GD_Miscellaneous:
if (!SwitchFromRootWindow(MISC_WINDOW))
{
PostError(getString(Couldnt_open_other_window_ERR));
ret = RET_QUIT;
}
break;
case GD_Blanking:
if (!SwitchFromRootWindow(BLANK_WINDOW))
{
PostError(getString(Couldnt_open_other_window_ERR));
ret = RET_QUIT;
}
break;
case GD_MouseCycling:
if (!SwitchFromRootWindow(MCYCLING_WINDOW))
{
PostError(getString(Couldnt_open_other_window_ERR));
ret = RET_QUIT;
}
break;
case GD_AutoPat:
NewPattern(GDX_AutoPat, &patterns[YP_AUTOSCR_PAT],
(struct Gadget *)STR_AutoScreen, ROOT_WINDOW);
break;
case GD_PopPat:
NewPattern(GDX_PopPat, &patterns[YP_POPWIN_PAT],
(struct Gadget *)STR_PopWindows, ROOT_WINDOW);
break;
case GD_Save:
DisableYakInterface();
EndNotify(&NotifyRequest);
SaveSettings(ENVARC_CONFIG_FILE);
CopyFile(ENVARC_CONFIG_FILE, ENV_CONFIG_FILE);
StartNotify(&NotifyRequest);
EnableYakInterface();
ret = RET_QUIT;
break;
case GD_Use:
DisableYakInterface();
EndNotify(&NotifyRequest);
SaveSettings(ENV_CONFIG_FILE);
StartNotify(&NotifyRequest);
ret = RET_QUIT;
break;
case GD_Cancel0:
ret = RET_QUIT;
break;
case GD_AutoCheck: /* toggle */
autopoint ^= TRUE;
break;
case GD_AutoPopCheck: /* toggle */
autopop ^= TRUE;
break;
case GD_KeyActCheck: /* toggle */
keyactivate ^= TRUE;
break;
case GD_ScrActCheck: /* toggle */
scractivate ^= TRUE;
break;
case GD_RMBActCheck: /* toggle */
rmbactivate ^= TRUE;
break;
case GD_MMBActCheck: /* toggle */
mmbactivate ^= TRUE;
break;
case GD_AutoPointDelay:
{
ULONG tmp;
GetAttr(SLIDER_Level,SL_AutoPointDelay,&tmp);
autopoint_delay = tmp;
}
break;
case MD_OPEN:
{
FileReqParams frp;
char *file;
frp.frp_Window = curwin;
frp.frp_Title = getString(FILEREQ_LOAD_STRING);
frp.frp_InitialFile = PrefsFile;
frp.frp_Flag1 = 0L;
DisableYakInterface();
if (file=OpenFileRequester(&frp))
{
LoadSettings(file);
FreeVec(PrefsFile);
PrefsFile = file;
InitRootGadgets();
}
EnableYakInterface();
}
break;
case MD_SAVE:
DisableYakInterface();
EndNotify(&NotifyRequest);
SaveSettings(ENVARC_CONFIG_FILE);
CopyFile(ENVARC_CONFIG_FILE, ENV_CONFIG_FILE);
StartNotify(&NotifyRequest);
EnableYakInterface();
break;
case MD_SAVEAS:
{
FileReqParams frp;
char *file;
frp.frp_Window = curwin;
frp.frp_Title = getString(FILEREQ_SAVEAS_STRING);
frp.frp_InitialFile = PrefsFile;
frp.frp_Flag1 = FRF_DOSAVEMODE;
DisableYakInterface();
EndNotify(&NotifyRequest);
if (file=OpenFileRequester(&frp))
{
SaveSettings(file);
if (CreateIcons)
{
struct DiskObject *dobj;
/* Get project icon */
if (!(dobj=GetDiskObject("ENV:Sys/def_yak")))
dobj = GetDefDiskObject(WBPROJECT);
if (dobj)
{
/* Set values */
dobj->do_DefaultTool = ProgramName;
dobj->do_Type = WBPROJECT;
/* Write icon */
PutDiskObject(file, dobj);
/* Free icon */
FreeDiskObject(dobj);
}
}
FreeVec(PrefsFile);
PrefsFile = file;
}
StartNotify(&NotifyRequest);
EnableYakInterface();
}
break;
case MD_HIDE:
case WMHI_CLOSEWINDOW:
HideInterface();
break;
case MD_ABOUT:
DisableYakInterface();
PostError(getString(About_Yak_STRING));
EnableYakInterface();
break;
case MD_QUIT:
ret = RET_QUIT;
break;
case MD_DEFAULT:
DisableYakInterface();
SetDefaultSettings();
InitRootGadgets();
EnableYakInterface();
break;
case MD_LASTSAVED:
DisableYakInterface();
LoadSettings(ENVARC_CONFIG_FILE);
InitRootGadgets();
EnableYakInterface();
break;
case MD_ACTIVE:
DisableYakInterface();
LoadSettings(ENV_CONFIG_FILE);
InitRootGadgets();
EnableYakInterface();
break;
case MD_CREATEICONS:
CreateIcons ^= TRUE;
break;
default:
break;
}
return ret;
}
/************************************************************************
*********************** SWITCHFROMROOTWINDOW() ************************
*************************************************************************
* Switch from root window to the sub-window whose ID is supplied.
* Returns TRUE or FALSE to indicate success.
*
*************************************************************************/
BOOL SwitchFromRootWindow(UBYTE WindowID)
{
CloseRootWindow();
return(ShowWindowID(WindowID));
}